package test.stub.ul2;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import services.Format;

public class OracleStub {
	
	public static Format oracleFormat(String ligne) {
		Format f = null;
		if(ligne.equals("F1 160")) {
			f = new Format("500", "A0");
		}
		else if(ligne.equals("F2 23 180")) {
			f = new Format("501", "17 B4");
		}
		else if(ligne.equals("F3 66 239")) {
			f = new Format("502", "42 EF");
		}
		else if(ligne.equals("F4 194 243")) {
			f = new Format("503", "C2 F3");
		}
		return f;
	}
	
	
	public static BufferedReader oracleStub(BufferedReader fOracle) throws IOException {
		String ligneJdt;
		File fileOracle = new File("resultOracle.txt");
        BufferedWriter bwOracle = new BufferedWriter(new FileWriter(fileOracle, false));
		try {
			while ((ligneJdt = fOracle.readLine()) != null) {
				Format f = OracleStub.oracleFormat(ligneJdt);
				bwOracle.write(f.getNumFormat() + " " + f.getValeur());
				bwOracle.newLine();
			}
			bwOracle.close();
		}catch(Exception e) {
			
		}
		BufferedReader fileOracleStub = null;
		try {
			String fichierOracle = "resultOracle.txt";
			fileOracleStub = new BufferedReader(new FileReader(new File(fichierOracle)));
		} catch (FileNotFoundException e) {
			System.out.println(e.getMessage());
		}
		return fileOracleStub;
	}


}
